# -*- py-indent-offset: 4 -*- 
# -*- tab-width: 8 -*- 
# -*- indent-tabs-mode: nil -*-
from etgui import *
import CmdNo,string
from FontBox import *
from PageLayout import *
from ListEditor import SimpleListEditor,AbstrListEditor
from ModelDictEditor import ModelDictEditor,AbstrModelDictEditor,SimpleModelDictEditor
from LayeredModelDictEditor import LayeredModelDictEditor
from PrefsMirrorEntries import MakeSplitStringListEditor,MakeSplitIncludeListEditor
## Context menu #########################################################################
class ContextMenuEditor(SimpleListEditor):
	SetDefaults=None
	changable=1
	def __init__(self,what):
		self.items=[]
		m=PotGuiModel()
		self.model=EditPotGuiModel(m)
		SimpleListEditor.__init__(self,what)
		self.model.AddModelObserver(self.Observe)
	def IsChangable(self,i):
		return self.changable
	def SetChangable(self,changable):
		self.changable=changable
		self.model.SetReadonly(not changable)
		self.model.AllValuesChanged()
	# set all questions to Changable
	CanNew=CanEdit=CanRename=CanCopy=CanDelete = IsChangable
	def CanSwap(self,i,j):
		return self.changable	
	def quoteColon(self,str):  # replace ':' with '_3a'
		list=string.split(str,':')
		return string.join(list,'_3a')
	def unquoteColon(self,str):  # replace '_3a' with ':'
		list=string.split(str,'_3a')
		return string.join(list,':')	
	def Split(self,strvalue):
		# and split value into a list
		if strvalue:
			list=string.split(strvalue,':')
			return map(self.unquoteColon,list)
		else:
			return []
	def Join(self,list):
		# join the list into a string
		if list:
			list=map(self.quoteColon,list)
			return string.join(map(string.strip,list),':')
		else:
			return ""
	def SetTools(self,toolnames_str,tools_str,newItem):
		# and split it into a list
		tools=self.Split(tools_str)
		# and split it into a list
		toolnames=self.Split(toolnames_str)

		# maybe one of the two lists is too short
		l=min(len(tools),len(toolnames))
		# set the items into a new model
		items=[]
		for i in range(l):
			items.append( (toolnames[i],tools[i]) )
		# default value for new entry
		if newItem:
			items.append( ("Edit","SniffEdit") )
		self.SetItems(items)
	def GetTools(self):
		toolname_list=[]
		tool_list=[]
		for toolname,tool,in self.items:
			toolname_list.append(toolname)
			tool_list.append(tool)
		toolnames=self.Join(toolname_list)
		tools=self.Join(tool_list)
		return toolnames,tools
	def MakePreview(self):
		return ModelContainer(
			self.model,
			PotGuiTextView("Tool",TextView(),Point(200,100))
		)
	def DoCopy(self,i):
		return "Copy of %s" %self.items[i]
	def Observe(self,model,slot):
		i=self.GetSelected()
		self.UpdateModel(i)
	def UpdateModel(self,i):
		if i>=0: 
			tool=self.model.GetValue("Tool")
			self.items[i]=(self.items[i][0],tool)
	def DoMakeItem(self,toolname_tool):
		toolname,tool=toolname_tool
		return TextItem(toolname)
	def _SelectionChanged(self,i):
		SimpleListEditor._SelectionChanged(self,i)
		self.model.Apply()
		try:
			toolname,tool=self.items[i]
			self.UpdateModel(i)
		except:
			toolname,tool= "",""
		# allow a modification of the model
		self.model.SetReadonly(0)
		self.model.SetValue("Tool",tool)
		# go back to the readonly state
		self.SetChangable(self.changable)

	def DoCopy(self,i):
		toolname,tool=self.items[i]
		return self.ShowEditDialog("Copy",(("Copy of %s"%toolname),tool))
	def ShowEditDialog(self,how,toolname_tool):
		m=PotGuiModel()
		toolname,tool=toolname_tool
		m.SetValue("Name",toolname)
		retval=ShowSubDialog("%s %s" %(how,self.what),
			m,
			PotTextField("Name")
		)
		if retval:
			return m.GetValue("Name"),tool

		else:
			return None
	def DoNew(self,i):
		return self.ShowEditDialog("Edit",("NewTool",""))
	def DoRename(self,i):
		return self.ShowEditDialog("Rename",self.items[i])


## File Type ############################################################################
class FileTypeModelDictEditor(LayeredModelDictEditor):
	derivedFrom=None
	isNewItem=0
	def __init__(self,model,path,what,proj=0):
		self.proj=proj
		if not self.IsPreference():
			self.show_prefs_file_types=0
			self.label_copy_for_editing="Add File Type"
			self.label_dele="Remove File Type"
		LayeredModelDictEditor.__init__(self,model,path,what)

	def IsPreference(self):
		return self.proj==0
	def IsProject(self):
		return self.proj==1
	def IsNewProject(self):
		return self.proj==2
	def NewValue(self):
		return {
			"__frame__":"File_Types_Info",
			"Name" : "NewItem"
		}    
	def CopyFrom(self):
		LayeredModelDictEditor.CopyFrom(self)
		if self.IsNewProject():  # set "Load Files of Selected File Type" to true as default
			self.model.SetValue(self.MakePath(self.KeyAt(self.GetSelected())+".Is Default File Type"),1)
	def DoSelect(self,i):
		LayeredModelDictEditor.DoSelect(self,i)
		key=self.KeyAt(i)
		self.model.SetValue("PSEUDO.FileType_Merge.Select",key)
	def DoSetItems(self,model):
		if self.model is None:
			self.model=model
			model.AddModelObserver(self.Observe,self.path,self._GetCollView())
			model.AddModelObserver(self.ObserveGoto,"PSEUDO.Goto",self._GetCollView())
		items=model.GetIndex(self.path)
		if items is None:
			items=[]
		sortitems=[]
		for name in items:
			if self.show_prefs_file_types \
			or self.IsAtEditLevel(self.MakePath(name)):
				derrived_name=self.GetDerrivedName(name)
				if not derrived_name or not derrived_name in items:
					sortitem=(name,          0, name)
				else:
					sortitem=(derrived_name, 1, name)
				sortitems.append(sortitem)
		sortitems.sort()
		# take the 3rd element and put int into the real list
		self.items=map(lambda x:x[2],sortitems)
		return self.items

	def DoMakeItem(self,key_value):
		try:
			key,value=key_value
		except (TypeError,ValueError):
			key=key_value
		if not self.IsAtEditLevel(self.MakePath(key)):
			font=gItalicFont
		elif self.IsNewProject() and self.IsDefaultFileType(key):
			font=gBoldFont
		else:
			font=gSysFont
		items=[]
		if self.IsDerrived(key):
			items=[ TextItem(" ") ]
		items.append(self.MakeImageFor(key))
		items.append(TextItem(str(key),font=font))
		return HBox(items=items)
	def DoNew(self,i):
		self.isNewItem=1
		LayeredModelDictEditor.DoNew(self,i)
	def IsDerrived(self,name):
		return self.GetDerrivedName(name)!=None
	def MakeImageFor(self,name):
		iconname= self.model.GetValue(self.MakePath(name+".Icon"))
		if not iconname:
			iconname= ""
		return MakeImageItem(iconname)
	def IsDefaultFileType(self,name):
		return self.model.GetValue(self.MakePath(name+".Is Default File Type"))
	def GetDerrivedName(self,name):
		derrived=self.model.GetValue(self.MakePath(name+".Derived From"))
		if derrived=="undefined":
			derrived=None
		return derrived
	def GetDerrivedFrom(self):
		if self.derivedFrom is None:
			self.derivedFrom=PotGuiPopupButton("Derived From")
			self.UpdateDerrivedFrom()
		return self.derivedFrom
	def UpdateDerrivedFrom(self):
		if self.derivedFrom is None:
			return
		# clean the list
		self.derivedFrom.RemoveAllItems()
		# always provide a None
		self.derivedFrom.AddItem("<None>","undefined")
		# our own name
		name=self.submodel.GetValue("Name")
		for i in self.items:
			# show only if not our self and not derrived
			if i!=name and not self.IsDerrived(i) \
				and (self.IsPreference() or self.IsAtEditLevel(self.MakePath(i))):
				self.derivedFrom.AddItem(i,i)
	def ObserveGoto(self,model,path):
		self.UpdateButtons()
	def Observe(self,model,path):
		ModelDictEditor.Observe(self,model,path)
		self.UpdateDerrivedFrom()
	def LoadDefaultFileTypeChanged(self,model,slot):
		self.Reload()
	def ObserveMerge(self,model,path):
		if path=="PSEUDO.SetForAll.Done":
			self.ObserveReload(model,path)
		
	def MakeMergeOptions(self):
		if PotGuiVObj_InAddMarkButtons():
			self.model.AddModelObserver(self.ObserveMerge)
			return HBox(
				align=eVObjVBase,
				items=[
					"Merge Options:", 
					PotGuiVObj("PSEUDO.FileType_Merge.Replace",TextItem("Replace")),
					PotGuiVObj("PSEUDO.FileType_Merge.Add",TextItem("Add")),
					PotGuiVObj("PSEUDO.FileType_Merge.Delete",TextItem("Delete")),
				]
			)
		else:
			return None
	sections=None
	def GetSections(self,model):
		if self.sections:
			return self.sections
		self.sections=sections=Sections()
		if self.IsNewProject():
			sections.loadFileType=PotGuiToggleButton("Is Default File Type","Load Files of Selected File Type")
			model.AddModelObserver(self.LoadDefaultFileTypeChanged,"Is Default File Type",sections.loadFileType)
			sections.loadFileTypeFiller=Filler(gPoint5)
		else:
			sections.loadFileType=None
			sections.loadFileTypeFiller=None

		sections.general=NamedSection(
			"General",   # page selector
			Form(
				items=[
				"Signatures",PotTextField("Signatures"),
				"Type",PotTextField("Type"),
				"Directory",PotTextField("Directory")
				]
			)
		)
		self.context_menu_editor=ContextMenuEditor("Context Menu")
		self.context_menu_editor.model.AddModelObserver(self.ContextMenuListObserver)
		model.AddModelObserver(self.ContextMenuObserver)
		sections.context_menu=NamedSection(
			"Context Menu",   # page selector
			MakeModelDictEditorLayout(self.context_menu_editor,0,"Corresponding Command",1,scroller_size=Point(125,100)),
#			MakeListEditorLayout(ContextMenuEditor("Context Menu")),
#			AdvancedButton(self.ShowContextMenuEditor,"Context menu..."),
		)
		sections.build_system=NamedSection(
			"Build System",   # page selector
			Form(
				items=[
					"General Makefile",PotGuiFileSelector("General Makefile",gTextFieldLen,"File"),  
					"Generated From",MakeFieldLayout(self.GetDerrivedFrom())
				]
			)
		)
		if self.IsPreference():
			isDefaultFileType=PotGuiToggleButton("Is Default File Type","Is Default File Type")
		else:
			isDefaultFileType=None
		sections.advanced=NamedSection(
			"Advanced",   # page selector
			MakeSectionLayout(
				Form(
					items=[
						"Source Code Parser",PotGuiFileSelector("Parser",gTextFieldLen,"Parser"),  
						"Icon for File Type",PotGuiFileSelector("Icon",gTextFieldLen,"Icon"),
##						"Retriever Priority",PotTextField("Retriever Priority")
					]
				),
				PotGuiToggleButton("Add/Remove Automatically","Add/Remove automatically to/from Project"),
				PotGuiToggleButton("Object Directory","Generated in Object Directory"),
				isDefaultFileType
			),
		)
		return sections
	def DoMakePreview(self,model):
		sections=self.GetSections(model)
		if gTabSheetStyle:
			return MakePageLayout(
				eVObjHExpand|eVObjVExpand,
				sections.loadFileType,
				TabSheetOrPageLayout(
					eVObjHExpand|eVObjVExpand,
					sections.general,
					sections.context_menu,
					sections.build_system,
					sections.advanced
				)
			)
		else:
			return MakePageLayout(
				eVObjHExpand|eVObjVCenter,
				sections.loadFileType,
				sections.loadFileTypeFiller,
				TabSheetOrPageLayout(
					eVObjHExpand|eVObjVCenter,
					sections.general
				)
			)
	def DoMakeItemEditView(self,model):
		if not gTabSheetStyle:
			sections=self.GetSections(model)
			return MakePageLayout(
				eVObjHExpand|eVObjVExpand,
				sections.loadFileType,
				TabSheetOrPageLayout(
					eVObjHExpand|eVObjVCenter,
					sections.build_system,
					sections.project_management,
					sections.advanced
				)
			)
		else:
			return TextItem("OOOPS!")
	if gTabSheetStyle:
		DoEdit=None
	def DoEditDone(self):
		self.Reload()

	in_ContextMenuObserver=0 # to avoid infinite loops
	def ContextMenuObserver(self,*args):
		if self.in_ContextMenuObserver:
			return
		self.in_ContextMenuObserver=1
		changable=self.submodel.IsValueChangable("Tools")
		self.context_menu_editor.SetChangable(changable)
		toolnames=self.submodel.GetValue("Tool Names")
		tools=self.submodel.GetValue("Tools")
		self.context_menu_editor.SetTools(toolnames,tools,self.isNewItem)
		#print "ContextMenuObserver",args
		self.in_ContextMenuObserver=0
		
	def ContextMenuListObserver(self,*args):
		if self.in_ContextMenuObserver:
			return
		self.in_ContextMenuObserver=1
		#print "ContextMenuListObserver",args
		toolnames=self.submodel.GetValue("Tool Names")
		tools=self.submodel.GetValue("Tools")
		ntoolnames,ntools=self.context_menu_editor.GetTools()
		# set values that have changed
		if ntoolnames!=toolnames:
			#print "Tool names",ntoolnames
			self.submodel.SetValue("Tool Names",ntoolnames)
		if ntools!=tools:
			self.submodel.SetValue("Tools",ntools)
			#print "Tools",ntools
		self.in_ContextMenuObserver=0
 
	## Show/Hide preferences file types...
	show_prefs_file_types=1
	show_prefs_button=None
	show_prefs_labels=["Show All","Hide Unused"]
	def ShowPrefsFileTypes(self):
		self.show_prefs_file_types=not self.show_prefs_file_types
		self.show_prefs_button.SetLabel(self.show_prefs_labels[self.show_prefs_file_types])
		self.Reload()
		self.Select(self.GetSelected())
	def MakeShowPrefsFileTypes(self):
		self.show_prefs_button=self.NewButton(self.show_prefs_labels[self.show_prefs_file_types],self.ShowPrefsFileTypes)
		return self.show_prefs_button
	def GetActionButtonConstructors(self):
		result=LayeredModelDictEditor.GetActionButtonConstructors(self)
		if not self.IsPreference():
			result.append(self.MakeShowPrefsFileTypes)
		return result


## Platform #############################################################################
class PlatformModelDictEditor(LayeredModelDictEditor):
	adaptors=(
		# model                    adaptor                        exec         prompt
		( "None",                  "None",                        "",          ""           ),
		( "ExternAdaptor",         "External debugger",           "",          ""           ),
		( "Gdb3Adaptor",           "gdb 3",                       "gdb",       "(gdb)"      ),
		( "Gdb4Adaptor",           "gdb 4",                       "gdb",       "(gdb)"      ),
		( "DecDbxAdaptor",         "dbx (Digital UNIX, ULTRIX)",  "dbx",       "(dbx)"      ),
		( "HpXdbAdaptor",          "xdb (HP-UX)",                 "xdb",       ">"          ),
		( "HpDdeAdaptor",          "dde (HP-UX)",                 "dde -do \"alias sniff_break(x) bre x; view -loc x; lis bre\"",  "dde>" ),
		( "HpDdePxAdaptor",        "dde Px (HP-UX)",              "dde -do \"alias sniff_break(x) bre x; env x; lis bre\"",        "dde>" ),
		( "IbmDbxAdaptor",         "dbx (AIX)", "dbx",            "(dbx)"      ),
		( "LaDbxAdaptor",          "DECladebug (Digital UNIX)",   "ladebug",   "(ladebug)"  ),
		( "SunDbxAdaptor",         "dbx (SunOS 4)",               "dbx",       "(dbx)"      ),
		( "SparcWorksDbxAdaptor",  "dbx (SparcWorks)",            "dbx",       "(dbx)"      ),
		( "SgiDbxAdaptor",         "dbx (IRIX)",                  "dbx",       "(dbx)"      ),
		( "SniDbxAdaptor",         "dbx (SINIX)",                 "dbx",       "(dbx)"      ),
		( "ScoDbxtraAdaptor",      "dbxtra (SCO)",                "dbxtra",    "(dbxtra)"   ),
		( "EDebugAdaptor",         "debug (UnixWare)",            "debug",     "debug>"   ),
		( "JavaAdaptor",           "sniffjdb (Java)",             "sniffjdb",  "(sniffjdb)" )
	)
	def NewValue(self):
		return {
			"__frame__":"Platform_Info",
		}
	sections=None
	def GetSections(self,model):
		if self.sections:
			return self.sections
		self.executable=PotGuiFileSelector("DebuggerExecutable",gTextFieldLen,"Executable")
		self.prompt=PotTextField("DebuggerPrompt")
		self.model.AddModelObserver(self.AdaptorChanged,"",self.prompt) # observer for setting exec and prompt on adaptor switch
		whichAdaptor=PotGuiPopupButton("DebuggerAdaptor")
		for m,a,e,p in self.adaptors:
			whichAdaptor.AddItem(a,m)

		self.sections=sections=Sections()
		sections.remote_settings=NamedSection(
			"Remote Settings",
			Form(
				items=[
					"Host",PotTextField("Host"),
					"Wait",HBox(
						align=eVObjVCenter|eVObjHLeft,
						items=[
						PotGuiIntField("ShellWait",IntField(-1,2,0,99)),
						TextItem("Seconds for Shell to Become Ready")
						]
					),
				]
			),
			Form(
				items=[
					"User Name",PotTextField("UserName"),
					"Remote Host SNIFF_DIR",PotGuiDirSelector("SniffDir",gTextFieldLen),
				]
			)
		)
		sections.make_support=NamedSection(
			"Make Support",   # page selector
			Form(
				items=[
					"Make Command",PotTextField("MakeCommand"),
					"Platform Makefile",PotTextField("PlatformMakefile"),
					"Object Directory",PotTextField("ObjectDir"),
					"Target Directory",PotTextField("TargetDir")
				]
				+MakeSplitIncludeListEditor(model,"IncludeMacro","Platform Includes","-I")
				+MakeSplitStringListEditor(model,"PreprocessorSwitch","Platform Defines","-D")
			)
		)
		sections.debugger=NamedSection(
			"Debugger",
			Form(
				items=[
					"Adaptor",MakeFieldLayout(whichAdaptor),
					"Executable",self.executable,
					"Prompt",self.prompt
				]
			)
		)
		if EnvGetBool("Crisp.VisibleInGUI",0):
			popup=PotGuiPopupButton("CrispParser")
			def UpdatePlatformDefaultPopup(model,path='',popup=popup):
				popup.RemoveAllItems()
				itemsList=Cast(model).GetIndex("CrispParserInfo")
				v=None
				if itemsList:
					itemsList.sort()
					for v in itemsList:
						popup.AddItem(v,v)   # (display, model)
				if not v:
					popup.AddItem("","")
			self.model.AddModelObserver(UpdatePlatformDefaultPopup,"CrispParserInfo")
			sections.crisp=NamedSection(
				"Crisp Parser",   # page selector
				Form(
					items=[
						"Crisp Parser",popup
					]
				)
			)
		else:
			sections.crisp=None
		return sections
	def DoMakePreview(self,model):
		sections=self.GetSections(model)
		return TabSheetOrPageLayout(
			eVObjHExpand|eVObjVCenter,
			sections.debugger,
			sections.make_support,
			sections.remote_settings,
			sections.crisp
		)
	DoEdit=None
	DoMakeItemEditView=None
	def AdaptorChanged(self,model,slot):
		#print "AdaptorChanged",model,slot
		new=Cast(model).GetValue(slot)
		i=string.rfind(slot,'.')   # XXX find better solution...
		path=slot[:i+1] # take also the '.'
		for m,a,e,p in self.adaptors:
			if new==m:
				self.model.SetValue(path+"DebuggerExecutable",e)
				#self.executable.SetSlot(path+"DebuggerExecutable")
				self.model.SetValue(path+"DebuggerPrompt",p) 
				#self.prompt.SetSlot(path+"DebuggerPrompt")


## Commands #############################################################################
class CommandsModelDictEditor(ModelDictEditor):
	# 'static' variables holding the command tables
	command_items=(    
			# display                     model
			( "Check Out",                 "CheckOut"             ),
			( "Check Out Project",         "CheckOutProject"      ),
			( "Create Repository File",    "CreateRepositoryFile" ),
			( "Check In",                  "CheckIn"              ),
			( "Lock",                      "Lock"                 ),
			( "SetWork File ReadOnly",     "SetWorkFileReadOnly"  ),
			( "Is Different",              "IsDifferent"          ),
			( "DiffText_W_V",              "DiffText_W_V"         ),
			( "DiffText_V_V",              "DiffText_V_V"         ),
			( "Update Project",            "UpdateProject"        ),
			( "Update File",               "UpdateFile"           ),
			( "Unlock",                    "Unlock"               ),
			( "Break Lock",                "BreakLock"            ),
			( "Delete Version",            "DeleteVersion"        ),
			( "Set Description",           "SetDescription"       ),
			( "Set Symbol",                "SetSymbol"            ),
			( "Delete Symbol",             "DeleteSymbol"         ),
			( "Change Comment",            "ChangeComment"        ),
			( "Description",               "Description"          ),
			( "History",                   "History"              ),
			( "Symbol List",               "SymbolList"           ),
			( "History of Revision",       "HistoryOfRevision"    ),
			( "Comment",                   "Comment"              ),
			( "Lockers",                   "Lockers"              ),
			( "Repository Dir",            "RepositoryDir"        ),
			( "Repository File",           "RepositoryFile"       ),
			( "Temp Dir",                  "TempDir"              ),
			( "Temp File",                 "TempFile"             ),
			( "Branch Def",                "BranchDef"            ),
			( "Repository Check Def",      "RepositoryCheckDef"   ),
			( "Check Repository Dir",      "CheckRepositoryDir"   ),
			( "Check Repository File",     "CheckRepositoryFile"  ),
			( "Date of Repository File",   "DateOfRepositoryFile" ),
			( "Create Repository Dir",     "CreateRepositoryDir"  ),
			( "Test Tool",                 "TestTool"             ),
			( "Constructor",               "Constructor"          ),
			( "Destructor",                "Destructor"           )
		)
	def DoGetButtonConstructors(self):
		return []  
	def DoSetItems(self,model):
		if self.model is None:
			self.model=model
			model.AddModelObserver(self.Observe,self.path,self._GetCollView())
		self.items=model.GetIndex(self.path)
		if self.items is None:
			self.items=[]
		return self.items  
	def DoMakeItem(self,key_value):
		for u,v in self.command_items:
			if v==key_value:
				return TextItem(str(u))
		return TextItem(str(key_value))   
	def DoMakePreview(self,model):
		return PotGuiTextView("",TextView(),Point(300,200))
	DoEdit=None


## VCS ##################################################################################
class VCSModelDictEditor(LayeredModelDictEditor):
	def NewValue(self):
		return {
			"__frame__":"VCS_Tool",
		}
	def CanAdvanced(self,i):   # advanced button only enabled for ClearCase
		i=self.GetSelected()
		if string.find(self.KeyAt(i),"ClearCase")!=-1 or string.find(self.KeyAt(i),"Clear Case")!=-1:
			return 1
		return 0
	advanved_dialog=None
	def Advanced(self):
		if self.advanved_dialog is None:
			self.advanved_dialog=self.MakeAdvancedDialog(EditPotGuiModel(self.model))
		self.advanved_dialog.ShowUnderMouse()
	def MakeAdvancedDialog(self,model):
		path="GUI.ClearCase"+'.'
		enablePath=(path+"UpdateEnabled")
		enableItem1=Form(
			items=[
				"Update Log File",PotGuiFileSelector(path+"UpdateLogFile",gTextFieldLen,"Log File"),
				"Update Interval",PotGuiIntField(path+"UpdateInterval",IntField(-1,10,10))
			]
		)
		enableItem2=PotGuiToggleButton(path+"ShowDialog","Show Confirmation Dialog")
		FieldEnabler(self.model,enablePath,
			items=[
				enableItem1,
				enableItem2
			]
		)
		enableItem3=PotGuiToggleButton(path+"SharingEnabled", "Enable Symbol Sharing")
		enableItem4=PotGuiToggleButton(path+"ShareAsync", "Do Sharing Asynchronously")
		FieldEnabler(self.model,path+"SharingEnabled",
			items=[
				enableItem4
			]
		)
		page=MakePageLayout(eVObjHExpand|eVObjVCenter,
			MakeBorderedSectionLayout("Symbol Update",
				PotGuiToggleButton(path+"UpdateEnabled","Enable Automatic Update"),
				enableItem1,
				enableItem2
			),
			MakeBorderedSectionLayout("Symbol Sharing",
				enableItem3,
				enableItem4
			)
		)	
		return MakeOkCancelDialog("ClearCase Options",EditPotGuiModel(model),page)
	if gTabSheetStyle:
		pass
	else:
		label_edit="Edit..."   # other label for VCS
	def MakeAdvancedButton(self):
		return self.NewButton("More Options...",self.Advanced,self.CanAdvanced)
	def MakeOthersButton(self):   # for the additional VCS integrations ftp site
		return self.NewButton("Others...",self.Others,self.CanOthers)
	def CanOthers(self,i):
		return 1
	def Others(self):
		ShowAlert(eAlertMessage,"Additional Integrations can be found\n \
			in Europe: @Iftp.takefive.co.at/pub/SNiFF/integrations@I\n \
			in USA: @Iftp.takefive.com/pub/SNiFF/integrations@I")
	def GetActionButtonConstructors(self):
		return LayeredModelDictEditor.GetActionButtonConstructors(self)+ \
			[self.MakeAdvancedButton,self.MakeOthersButton]
	if gTabSheetStyle:
		def DoMakePreview(self,model):
			return self.DoMakeItemEditView(model)
		DoEdit=None
	def DoMakeItemEditView(self,model):
		return MakePageLayout(eVObjHExpand|eVObjVExpand,
			MakeModelDictEditorLayout(CommandsModelDictEditor(model,"","Commands"),0,"Command Specification",1)
		)


## Text Properties ######################################################################
class TextPropertiesModelDictEditor(ModelDictEditor):
	# 'static' variables holding the editor/docu editor tables
	all_items=(
		# display                    model         for all entries
		( "All",                     "All"         ),
		# display                    model         for SE symbol highlighting
		( "Code",                    "Code"        ),
		( "Comment",                 "Comment"     ),
		( "Macro",                   "Macro"       ),
		( "Class",                   "Class"       ),
		( "Instance Variable",       "InstVar"     ),
		( "Method Definition",       "MethodDef"   ),
		( "Method Implementation",   "MethodImpl"  ),
		( "Function",                "Function"    ),
		( "Friend",                  "Friend"      ),
		( "Type Definition",         "TypeDef"     ),
		( "Variable",                "Variable"    ),
		( "Constant",                "Const"       ),
		( "Enumeration",             "Enum"        ),
		( "Enumeration Item",        "EnumItem"    ),
		( "User Defined",            "UserDefined" ),
		# display                    model         for SE keyword highlighting
		( "Keyword",                 "Keyword"     ),
		( "String",                  "String"      ),
		# display                     model        for DE
		( "H1",                      "H1"          ),
		( "H2",                      "H2"          ),
		( "H3",                      "H3"          ),
		( "H4",                      "H4"          ),
		( "H5",                      "H5"          ),
		( "H6",                      "H6"          ),
		( "P",                       "P"           ),
		( "PRE",                     "PRE"         )
	)
	mb=fontBox=fontBoxAuto=None
	boxOld=boxNew=1
	automodel=None
	def __init__(self,model,path,what):
		ModelDictEditor.__init__(self,model,path,what)
		self.InitAuto()
	def InitAuto(self):   # set 'All' entry and values for automatic font box
		self.model.SetValue(self.MakePath("All.Font.Font"),"auto")
		self.model.SetValue(self.MakePath("All.Font.Style"),"auto")
		self.model.SetValue(self.MakePath("All.Font.Size"),0)
	def DoGetButtonConstructors(self):
		return []
	def ItemChanged(self,model,path):
		if self.KeyAt(self.GetSelected())=="All":
			index=self.model.GetIndex(self.path)
			index.remove("All")
			for i in index:
				newValue=self.model.GetValue(self.MakePath("All"+'.'+path))
				if newValue=="auto" or newValue==0:
					newValue=self.automodel.GetValue(self.MakePath(i+'.'+path))
				self.model.SetValue(self.MakePath(i+'.'+path),newValue)
		self.Reload()
	def DoEditBegin(self):
		self.InitAuto()
		if self.automodel==None:   # model for automatic
			self.automodel=PotGuiModel(self.model)
		self.Select(1)   # select the first item after 'All'
	def DoEditEnd(self):
		self.model.RemoveAt(self.MakePath("All"))   # get rid of the 'All' entry
	def DoSelect(self,i):
		ModelDictEditor.DoSelect(self,i)
		if self.mb:   # switch font boxes
			key=self.KeyAt(i)
			if key=="All":
				self.boxNew=0
			else:
				self.boxNew=1
			if self.boxOld!=self.boxNew:
				self.boxOld=self.boxNew
				self.mb.PageShow(self.boxNew)
	def DoMakeItem(self,key):
		key=str(key)
		if key=="All":
			return StyledTextItem(key)
		font=GetFontFromModel(self.model,self.MakePath(key+".Font"))
		ink=GetInkFromModel(self.model,self.MakePath(key+".Color"))
		for u,v in self.all_items:
			if v==key:
				key=u
				break
		return StyledTextItem(key,font=font,ink=ink)
	def DoMakePreview(self,model):
		self.fontBoxObjAuto=FontBoxObj(model,"Font",None,0,1)   # automatic font box
		self.fontBoxAuto=self.fontBoxObjAuto.MakeVObj()
		model.AddModelObserver(self.ItemChanged,"",self.fontBoxAuto)
		self.fontBoxObj=FontBoxObj(model,"Font","Color",1)   # normal font box
		self.fontBox=self.fontBoxObj.MakeVObj()
		model.AddModelObserver(self.ItemChanged,"",self.fontBox)
		self.mb=MultiBox()
		self.mb.PageAdd(self.fontBoxAuto)
		self.mb.PageAdd(self.fontBox)
		return self.mb
	def DoEdit(self,i):
		pass


## Documentable Symbol ##################################################################
class DocSymbolModelDictEditor(ModelDictEditor):
	# 'static' variables holding the doc symbols table
	symbol_items=(
		# display                       model
		( "Classes, Structs, Unions",   "Class" ),
		( "Functions",                  "Func"  ),
		( "Variables",                  "Gvar"  ),
		( "Enumerations",               "Enum"  ),
		( "Types",                      "Type"  ),
		( "Macros",                     "Macro" ),
		( "Methods",                    "Meth"  ),
		( "Instance Variables",         "Ivar"  ),
		( "Internal Enums",             "IEnum" ),
		( "Internal Types",             "IType" ),
	)
	# 'static' variable of items that can be public/protectec/private
	is_part_of_class=("Meth", "Ivar", "IEnum", "IType")

	enableItem=None
	def DoGetButtonConstructors(self):
		return []    
	def DoMakeItem(self,key):
		if self.IsDocumentable(key):
			font=gBoldFont
		else:
			font=gSysFont
		for u,v in self.symbol_items:
			if v==key:
				return TextItem(str(u),font=font)
		return TextItem(str(key),font=font) 
	def DoSelect(self,i):
		ModelDictEditor.DoSelect(self,i)
		if self.enableItem:
			self.enableItem.Enable(self.IsEnabled(i))
	def IsDocumentable(self,key):
		doc_path=self.MakePath(key+".Documentable")
		return self.model.GetValue(doc_path)
	def ObserveDocumentable(self,model,slot):
		self.Reload()
	def IsEnabled(self,i):
		value=self.KeyAt(i)
		return value in self.is_part_of_class
	def DoEdit(self,i):
		doc_path=self.Slot("Documentable")
		self.model.SetValue(doc_path,not self.model.GetValue(doc_path))
	def DoMakePreview(self,model):
		self.enableItem=VBox(
			items=[
				PotGuiToggleButton("Private","Private"),
				PotGuiToggleButton("Protected","Protected"),
				PotGuiToggleButton("Public","Public")
			]
		)
		model.AddModelObserver(self.ObserveDocumentable,"Documentable",self.enableItem)
		return VBox(
			items=[
				PotGuiToggleButton("Documentable","Documentable"),
				Filler(gPointSectionGap),
				self.enableItem
			]
		)
